﻿Imports Hijri_API.Converter
Imports Hijri_API.Converter.Dates
Imports System.Net

Public Class Calendar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Dim dd As New Dates
    Private Sub Calendar_LoadComplete(sender As Object, e As EventArgs) Handles Me.LoadComplete
        Dim d As Integer, m As Integer, y As Integer, res As String, result As String = "Error in Type", yy As String = "", Auth As String = ""
        d = 1
        m = CInt(Request.QueryString.Item("month"))
        y = CInt(Request.QueryString.Item("year"))

        yy = CStr(y)
        Auth = Request.QueryString.Item("auth")
        If Auth = "" Or m = 0 Or m > 12 Or y = 0 Then
            result = "Parameter Error"
            Auth = "Error"
            GoTo ErrorJump
        End If


        Do Until yy.Length = 4
            yy = "0" + yy
        Loop
        If y > 1355 And y < 1501 Then
            result = dd.HijriToGreg(CStr(d) + "-" + CStr(m) + "-" + yy, "ddMMyyyy")
            result = result + dd.WeekDay(result)
        Else
            result = dd.H2GZurich(d, m, y)
        End If
        If m < 12 Then
            m = m + 1
        Else
            m = 1
            y = y + 1

        End If
        yy = CStr(y)
        Do Until yy.Length = 4
            yy = "0" + yy
        Loop
        If y > 1355 And y < 1501 Then
            res = dd.HijriToGreg(CStr(d) + "-" + CStr(m) + "-" + yy, "ddMMyyyy")
            res = res + dd.WeekDay(res)
        Else
            res = dd.H2GZurich(d, m, y)
        End If
        result = result + "-" + res
ErrorJump:
        OutputLabel.Text = result
    End Sub
End Class